<template>
  <di v-if="user">
    <van-cell title="昵称" is-link to="/user/edit" @click="toEdit('username','昵称',user.username)" :value="user.username" />
    <van-cell title="账号" :value="user.userAccount" />
    <van-cell title="头像" is-link to="/user/edit" @click="toEdit('avatarUrl','头像',user.avatarUrl)" >
      <img :src="user.avatarUrl" style="height: 38px"/>
    </van-cell>
    <van-cell title="性别" is-link to="/user/edit" @click="toEdit('gender','性别',user.gender)" :value="user.gender" />
    <van-cell title="手机" is-link to="/user/edit" @click="toEdit('phone','手机',user.phone)" :value="user.phone" />
    <van-cell title="邮箱" is-link to="/user/edit" @click="toEdit('email','邮箱',user.email)" :value="user.email" />
    <van-cell title="创建时间" :value="user.createTime" />
  </di>

</template>


<script setup lang="ts">

import {useRouter} from "vue-router"
import {onMounted, ref} from "vue";
import {getCurrentUser} from "../services/user.ts";

const user = ref();

onMounted(async () => {
  user.value = await getCurrentUser();
})
// const user: userType = {
//   id: 111,
//   username: "ycc",
//   userAccount: "yccc",
//   avatarUrl: "https://router.vuejs.org/logo.svg",
//   gender: 1,
//   phone: "123123",
//   email: "sdfsf@qq.com",
//   createTime: new Date()
// };

const router = useRouter();
const toEdit = (editKey: string, editName: string, currentValue: any) => {
  router.push({
    path: "/user/edit",
    query: {
      editKey,
      editName,
      currentValue
    }
  });
}
</script>

<style scoped>

</style>